package com.intellagric.controller.module.trace_process;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TraceProcess;
import com.intellagric.service.traceability.trace_process.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/1/13
 * @DESC： 生产流程配置管理控制
 */
@Controller
public class ProcessController {

    @Autowired
    private ProcessService processService;

    /**
     * 添加生产流程配置信息
     * @Param process
     * @return ResponseMessage
     */
    @RequestMapping("/process/add")
    @ResponseBody
    public ResponseMessage add(TraceProcess process) {
        process.setId(UUID.randomUUID().toString().replaceAll("-",""));
        process.setCreateDate(new Date());
        process.setUpdateDate(new Date());
        return processService.addProcess(process);
    }

    /**
     * 删除生产流程配置信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/process/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return processService.deleteProcess(id);
    }

    /**
     * 修改生产流程配置信息
     * @Param process
     * @return ResponseMessage
     */
    @RequestMapping("/process/edit")
    @ResponseBody
    public ResponseMessage edit(TraceProcess process) {
        process.setUpdateDate(new Date());
        return processService.editProcess(process);
    }

    /**
     * 查询生产流程配置信息
     * @return Object
     */
    @RequestMapping("/process/{id}")
    @ResponseBody
    public TraceProcess get(@PathVariable String id) {
        return processService.getProcessById(id);
    }

    /**
     * 查询生产流程配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/list/{produceBatchId}")
    @ResponseBody
    public LayuiDataGridResult getList(@PathVariable String produceBatchId) {
        return processService.getProcessList(produceBatchId);
    }

    /**
     * 查询生产流程配置信息列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/{templateId}")
    @ResponseBody
    public LayuiDataGridResult getTree(@PathVariable String templateId) {
        return processService.getProcessTree(templateId);
    }

    /**
     * 查询生产流程配置信息列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/select/{templateId}")
    @ResponseBody
    public List<TraceProcess> getTreeSelect(@PathVariable String templateId) {
        return processService.getProcessTree(templateId).getData();
    }

    /**
     * 查询生产流程配置信息子级列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/sub")
    @ResponseBody
    public LayuiDataGridResult getSubTree(String parentId,String produceBatchId) {
        return processService.getProcessByParentId(parentId,produceBatchId);
    }

}
